*Joining couples*
clear

use "Data\dataset_with_singles.dta" 

gen ambition=.
replace ambition=1 if ambition_type_k_4_s==1
replace ambition=2 if ambition_type_k_4_s==4
replace ambition=3 if ambition_type_k_4_s==3
replace ambition=4 if ambition_type_k_4_s==2

drop ambition_type_k_4_s

sort pnr aar
by pnr: egen first_year=min(aar)
drop individual
gen individual=1 if aar==first_year
drop first_year

gen wage_start_mean_ambition_s_both=wage_start_mean_ambition_s
drop wage_start_mean_ambition_s
gen wage_growth_ambition_s_both=wage_growth_ambition_s
drop wage_growth_ambition_s

*Merge on men

merge 1:1 pnr aar using "Results\tab_B3\Scenario_2\sample2_men.dta", keepusing(ambition_type_k_4_s wage_start_mean_ambition_s wage_growth_ambition_s)

drop if _merge==2
drop _merge

gen ambition_type_sep=. if !missing(ambition_type_k_4_s)
replace ambition_type_sep=1 if ambition_type_k_4_s==2
replace ambition_type_sep=2 if ambition_type_k_4_s==4
replace ambition_type_sep=3 if ambition_type_k_4_s==3
replace ambition_type_sep=4 if ambition_type_k_4_s==1


drop ambition_type_k_4_s

gen wage_start_mean_ambition_s_m=wage_start_mean_ambition_s
drop wage_start_mean_ambition_s
gen wage_growth_ambition_s_m=wage_growth_ambition_s
drop wage_growth_ambition_s

*Merge on women

merge 1:1 pnr aar using "Results\tab_B3\Scenario_2\sample2_women.dta", keepusing(ambition_type_k_4_s wage_start_mean_ambition_s wage_growth_ambition_s)

drop if _merge==2
drop _merge

replace ambition_type_sep=1 if ambition_type_k_4_s==1 & koen=="2"
replace ambition_type_sep=2 if ambition_type_k_4_s==3 & koen=="2"
replace ambition_type_sep=3 if ambition_type_k_4_s==2 & koen=="2"
replace ambition_type_sep=4 if ambition_type_k_4_s==4 & koen=="2"

drop ambition_type_k_4_s

gen wage_start_mean_ambition_s_w=wage_start_mean_ambition_s
drop wage_start_mean_ambition_s
gen wage_growth_ambition_s_w=wage_growth_ambition_s
drop wage_growth_ambition_s

**Get partner types

//generate partners' ambition
by couple_id aar, sort: gen am_male = ambition if koen=="1" & relationship==1
by couple_id aar: gen am_female = ambition if koen=="2" & relationship==1
by couple_id aar: egen maxeduc = max(am_male)
by couple_id aar: replace am_male = maxeduc
drop maxeduc
by couple_id aar: egen maxeduc = max(am_female)
by couple_id aar: replace am_female = maxeduc
drop maxeduc

by couple_id aar, sort: gen am_sep_male = ambition_type_sep if koen=="1" & relationship==1
by couple_id aar: gen am_sep_female = ambition_type_sep if koen=="2" & relationship==1
by couple_id aar: egen max_am_sep = max(am_sep_male)
by couple_id aar: replace am_sep_male = max_am_sep
drop max_am_sep
by couple_id aar: egen max_am_sep = max(am_sep_female)
by couple_id aar: replace am_sep_female = max_am_sep
drop max_am_sep


**Save**
save "Results\tab_B3\Scenario_2\joining_couples.dta", replace


